package com.mililoan.service.module.system.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mililoan.common.bean.PageResultSet;
import com.mililoan.model.system.Param;
import com.mililoan.persist.system.ParamDao;
import com.mililoan.service.module.system.ParamBo;

/**
 * @ClassName: ParamBoImpl
 * @Description: 接口实现类
 * @author taochen 
 * @since 2017-08-26
 */
@Service("ParamBo")
public class ParamBoImpl implements ParamBo{	
	@Autowired
	private ParamDao paramDao;
	
	/**
	 * @Title: queryParamList
	 * @Description: 分页查询
	 * @param param
	 * @param page
	 * @param pageSize
	 * @return
	*/
	public PageResultSet<Param> queryParamList(Param param, int page, int pageSize) throws Exception{
		PageResultSet<Param> prs = paramDao.queryParamList(param, page, pageSize);
		return prs;
	}

	/**
	 * @Title: add
	 * @Description: 添加
	 * @param param
	 * @return
	 * @throws Exception 
	*/
	@Transactional(rollbackFor=Exception.class)
	public Long addParam(Param param) throws Exception {	
		return paramDao.add(param);
	}

	/**
	 * @Title: update
	 * @Description: 修改
	 * @param param
	 * @return
	 * @throws Exception 
	*/
	public Long updateParam(Param param) throws Exception {
		return paramDao.update(param);
	}

	/**
	 * @Title: delete
	 * @Description: 删除
	 * @param KeyId
	 * @return
	 * @throws Exception 
	*/
	public Long deleteParam(Long keyId) throws Exception {		
		return paramDao.delete(keyId);
	}

	/**
	 * @Title: queryParamById
	 * @Description: 查询单个对象
	 * @param KeyId
	 * @return
	 * @throws Exception 
	*/
	public Param getParamById(Long keyId) throws Exception {
		return paramDao.getParamById(keyId);
	}

	public Param getParamByKey(String paramKey) throws Exception {
		Param retParam = null;
		if(StringUtils.isEmpty(paramKey)){
			Param queryParam = new Param();
			queryParam.setParamKey(paramKey);
			
			List<Param> queryList = paramDao.queryParamAllList(queryParam);
			if(null !=queryList && queryList.size()>0){
				retParam = queryList.get(0);
			}			
		}
		
		return retParam;
	}
}